package com.lg.atp.sercurity;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.lg.atp.entity.TblUserInfo;
import com.lg.atp.service.IUserService;
import com.lg.atp.vo.user.UserVo;

@Component("userDetailsService")
public class UserDetailService implements UserDetailsService {

	
	@Autowired
	private IUserService iUserService;
	@Override
	public UserDetails loadUserByUsername(String userName)
			throws UsernameNotFoundException {
		 
		 TblUserInfo userInfo = iUserService.getUserRoleByAcc(userName);
		 if(userInfo != null){
			 UserVo user = JSONObject.parseObject(JSONObject.toJSONString(userInfo),UserVo.class);
			 return user;
		 }
         return null;  
	}

}
